
Ever wondered how to search for Power Automate workflow based on the action they use?
Here is a brief tutorial on how to create a script that will look for Power Automate Workflows that uses SharePoint or OneDrive Actions
Before you can run Script below you need the follower
- PowerShell- "Microsoft.PowerApps.Administration.PowerShell" Module- "Microsoft.PowerApps.PowerShell" Module- "AzureAD" Module"
To install all the Modules we will need, just run the following line
Install-Module -Name Microsoft.PowerApps.Administration.PowerShellInstall-Module -Name Microsoft.PowerApps.PowerShell -AllowClobberInstall-Module -Name AzureAD
To allow us to access our M365 Tenant we need to run the following command
Note: You need to login twice because youll be logging in to Power Automate Site and to Azure AD site.
Note #2: The reason why we need to login to Azure AD because we will use that to get the display name of our users latera
Add-PowerAppsAccountConnect-AzureAD
After getting Authenticated, kindly run the follow script to start getting all Power Automate workflow that uses SharePoint related Action(or could also be OneDrive related Actions)
$environments = Get-FlowEnvironment #This is to get all available Environment in our Power Automte Tenant$csvVariable = @()foreach($environ in $environments.EnvironmentName) #Cycle to all Environments{$flows = Get-AdminFlow –EnvironmentName $environforeach ($flow in $flows) #Loop to each PowerAutomate workflow Available{$WFDetails = $flow | Get-AdminFlow#shared_sharepointonline is the reference for searchin any related SharePoint action. If you want to search for Onedrive actions, just change it to "shared_onedriveforbusiness"if([bool]($WFDetails.Internal.properties.connectionReferences -match "shared_sharepointonline")){$obj = New-Object -TypeName psobject$obj | Add-Member -MemberType NoteProperty -Name "Environtment" -Value $flow.EnvironmentName$obj | Add-Member -MemberType NoteProperty -Name "FlowID" -Value $flow.FlowName$obj | Add-Member -MemberType NoteProperty -Name "FlowDisplayName" -Value $flow.DisplayName$obj | Add-Member -MemberType NoteProperty -Name "FlowAddress" -Value $flow.Internal.id$obj | Add-Member -MemberType NoteProperty -Name "Enabled" -Value $flow.Enabled$obj | Add-Member -MemberType NoteProperty -Name "FlowCreated" -Value $flow.CreatedTime$obj | Add-Member -MemberType NoteProperty -Name "LastModified" -Value $flow.LastModifiedTime#Get-AzureADUser helps us to get the Display Name of the Owner of the Workflow because PowerAutomate only holds ObjectID of the user unfortunately.$obj | Add-Member -MemberType NoteProperty -Name "Creator" -Value (Get-AzureADUser -ObjectId $flow.CreatedBy.objectId).DisplayName$owner = Get-AdminFlowOwnerRole –EnvironmentName $environ -FlowName $flow.FlowName$varOwner = @()$varGroupOwner = @()#Seperating Group Owner to User Owners|foreach ($singleOwner in $owner){switch ($singleOwner.PrincipalType){User {try {$varOwner += (Get-AzureADUser -ObjectId $singleOwner.PrincipalObjectId)}catch [System.Net.WebException],[System.IO.IOException] {}}Group{#Note we are searching for Group because we can also assign a Group as an Owner of the Power Automatetry {$varGroupOwner += (Get-AzureADGroup -ObjectId $singleOwner.PrincipalObjectId)}catch [System.Net.WebException],[System.IO.IOException] {}}}}$tempArray = $varOwner | Foreach {"$($_.DisplayName)"}$obj | Add-Member -MemberType NoteProperty -Name "OwnerUsers" -Value ($tempArray -join ',')$tempArray = $varGroupOwner | Foreach {"$($_.DisplayName)"}$obj | Add-Member -MemberType NoteProperty -Name "OwnerGroups" -Value ($tempArray -join ',')$csvVariable += $obj;}}}#Create a CSV file out of our results$csvVariable | Export-Csv '.\WorkflowResults.csv' -Force